package yxy.game.pm2.bean.db.newDao;

import yxy.apple.db.DbManager;
import yxy.game.pm2.bean.db.po.PassbarrierRecordPo;
import yxy.game.pm2.bean.db.po.StairwayRecordPo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liangjianbin
 * @date 2022/3/1 8:40
 **/
public class PassbarrierRecordDAO {
    private static final String
            REPLACE_ONE = "replace into `passbarrierRecord` (`pCode`,`code`,`date`,`recordCodes`,`isWin`,`infoA`,`infoB`," +
            "`degree`,`score`,`rank`,`updateTime`) " +
            "values (?,?,?,?,?,?,?,?,?,?,?)",
            SELECT_ALL = "select * from `passbarrierRecord` where `pCode` = ?",
            DELETE = "delete from `passbarrierRecord` where `pCode` = ? and `updateTime` != ?";

    public static List<PassbarrierRecordPo> getList(String playerCode) {
        return DbManager.instance().executeQueryObjectList(SELECT_ALL, new Object[]{playerCode}, PassbarrierRecordPo.builder);
    }

    public static boolean replace(List<PassbarrierRecordPo> poList) {
        List<Object[]> list = new ArrayList<>();
        for (PassbarrierRecordPo po : poList) {
            Object[] objects = new Object[]{po.getPlayerCode(), po.getCode(), po.getDate(), po.getRecordCodes(), po.isWin(),
                    po.getInfoA(), po.getInfoB(), po.getDegree(), po.getScore(), po.getRank(), po.getUpdateTime()};
            list.add(objects);
        }
        int[] ints = DbManager.instance().executeBatchCommand(REPLACE_ONE, list);
        return ints.length == poList.size();
    }

    public static void delete(String pCode, long updateTime) {
        int i = DbManager.instance().executeCommand(DELETE, new Object[]{pCode, updateTime});

    }


}
